#include <plc2llvm/Visitor/Visitor.h>
#include <plc2llvm/Visitor/StrategyFactory.h>
#include <plc2llvm/PLCScopeStack.h>
#include <plc2llvm/utils/Log.h>
#include <cxxabi.h>

Visitor::Visitor() {
    //初始化，可能需要
}

//释放单例类：策略类、作用域栈
Visitor::~Visitor(){
    delete StrategyFactory::getFactory();
    delete PLCScopeStack::getScopeStack();
    //TODO:通过查询总表释放作用域、作用域栈、符号
}

std::any Visitor::visitFunc_Decl(plcst::PLCSTParser::Func_DeclContext *ctx) {
    return StrategyFactory::getStrategy(int (ctx->getRuleIndex()))->invoke(ctx, this);
}

std::any Visitor::visitProg_Decl(plcst::PLCSTParser::Prog_DeclContext *ctx) {
    return StrategyFactory::getStrategy(int (ctx->getRuleIndex()))->invoke(ctx, this);
}

std::any Visitor::visitVar_Decls(plcst::PLCSTParser::Var_DeclsContext *ctx) {
    return StrategyFactory::getStrategy(int (ctx->getRuleIndex()))->invoke(ctx, this);
}

std::any Visitor::visitVar_Decl_Init(plcst::PLCSTParser::Var_Decl_InitContext *ctx) {
    return StrategyFactory::getStrategy(int (ctx->getRuleIndex()))->invoke(ctx, this);
}

std::any Visitor::visitVariable_List(plcst::PLCSTParser::Variable_ListContext *ctx) {
    return StrategyFactory::getStrategy(int (ctx->getRuleIndex()))->invoke(ctx, this);
}

std::any Visitor::visitVariable_Name(plcst::PLCSTParser::Variable_NameContext *ctx) {
    return StrategyFactory::getStrategy(int (ctx->getRuleIndex()))->invoke(ctx, this);
}

std::any Visitor::visitSimple_Spec_Init(plcst::PLCSTParser::Simple_Spec_InitContext *ctx) {
    return StrategyFactory::getStrategy(int (ctx->getRuleIndex()))->invoke(ctx, this);
}
